<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" />
    <p></p>
    <script>
      const debounce = (fn, duration = 1000) => {
        let timer;
        return (...args) => {
          clearTimeout(timer);
          timer = setTimeout(() => {
            fn(...args);
          }, duration);
        };
      };
      const inp = document.querySelector('input');
      const p = document.querySelector('p');
      // 监听 文本框 内容的变化，以防抖的方式输出当前文本框的值

      const handler = debounce(() => {
        p.innerText = inp.value;
      }, 100);

      inp.addEventListener('input', handler);
    </script>
  </body>
</html>

